CREATE OR REPLACE FUNCTION inc_nb_comments_function() RETURNS TRIGGER AS $$
    BEGIN
       UPDATE entries SET has_comments = has_comments + 1 WHERE entries.id = comments.id_entry;
    END;
$$ LANGUAGE plpgsql;

CREATE TRIGGER inc_nb_comments_trigger AFTER INSERT ON comments
FOR EACH ROW EXECUTE PROCEDURE inc_nb_comments_function();

